package com.tvunetworks.center.user.service;

import com.github.pagehelper.PageInfo;
import com.tvunetworks.center.common.model.LoginUser;
import com.tvunetworks.center.common.model.param.UpdateUserEmailParam;
import com.tvunetworks.center.common.model.vo.UserInfoVo;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.user.model.User;
import com.tvunetworks.center.user.model.json.ExcelData;
import com.tvunetworks.center.user.model.param.CreateUserParam;
import com.tvunetworks.center.user.model.param.MoveUserToOtherAdminParam;
import com.tvunetworks.center.user.model.param.PageSonUserParam;
import com.tvunetworks.center.user.model.param.SearchUserParam;
import com.tvunetworks.center.user.model.vo.CheckUserVo;
import com.tvunetworks.center.user.model.vo.GetUserByRoleIdVo;
import com.tvunetworks.center.user.model.vo.PageUserVo;
import com.tvunetworks.center.user.model.vo.UserIdWithEmail;

import java.io.IOException;
import java.util.List;
/**
 * @author Etan Yang
 * @data: 2021/6/4 19:05
 * @program: tvucc-aggregator
 * @description:
 */
public interface UserService {
    /**
     *
     * @param token token
     * @param serverName serverName
     * @return Result
     * @throws  IOException IOException
     */
    Result<LoginUser> getLoginUserAndCheckAuth(String token, String serverName) throws IOException;

    /**
     * 通过Userservice check登陆用户
     * @param token token
     * @throws  IOException 编译
     * @return Result
     */
    Result<LoginUser> getLoginUser(String token) throws IOException;

    /**
     *
     * @param token token
     * @return Result
     * @throws IOException IOException
     */
    Result<LoginUser> getLoginUserWithNoCheck(String token) throws IOException;


    /**
     *
     *  用  token 获取用户的完整信息
     *
     * @param token token code
     * @return user full info
     * @throws IOException IOException
     */
    Result<com.tvunetworks.center.common.model.User> getUserWithNoCheck(String token) throws IOException;

    /**
     * 通过Userservice check登陆用户并且检查用户在数据库中是否存在，不存在则创建
     * @param token token
     * @throws  IOException 编译
     * @return Result
     */
    Result<LoginUser> getLoginUserWithCheck(String token) throws IOException;

    /**
     *
     * @param token token
     * @return Result
     * @throws IOException IOException
     */
    Result<Void> logout(String token) throws IOException;

    /**
     *
     * @param email email
     * @param token token
     * @return Result
     */
    Result<String> getUserRole(String email, String token);

    /**
     *
     * @param user user
     */
    void add(User user);

    /**
     *
     * @return List
     */
    List<User> selectAll();

    /**
     *
     * @param loginUser loginUser
     * @param param param
     * @param  pageNum pageNum
     * @param pageSize pageSize
     * @return PageInfo
     */
    PageInfo<PageUserVo> pageUser(LoginUser loginUser, SearchUserParam param, int pageNum, int pageSize);

    /**
     *
     * @param email email
     * @return User
     */
    User getByEmail(String email);

    /**
     *
     * @param id id
     * @return User
     */
    User getById(String id);

    /**
     *
     * @return List
     */
    List<User> listUser();


    /**
     *
     * @param email email
     * @param pageNum pageNum
     * @param pageSize pageSize
     * @return PageInfo
     */
    PageInfo<UserIdWithEmail> pageAdminIdAndEmail(String email, Integer pageNum, Integer pageSize);

    /**
     * 修改用户权限 user->admin admin->user
     * @param userId userId
     * @param role role
     * @param loginUser 当前登录账号信息
     * @return int
     */
    int setRole(String userId, String role,LoginUser loginUser);

    /**
     * 设置用户是否可用
     * @param userId userId
     * @param active active
     * @return int
     */
    int setActive(String userId, String active);

    /**
     * 创建用户
     * @param loginUser loginUser
     * @param createUserParam createUserParam
     * @return Result
     */
    Result<String> createUser(LoginUser loginUser, CreateUserParam createUserParam);

    /**
     *
     * @param email email
     * @return LoginUser
     */
    LoginUser getLoginUserByEmail(String email);

    /**
     * 查询用户在setting页面可有的tab
     * @param role role
     * @return String
     */
    String getSettingTab(String role);

    /**
     * 列出所有 Admin
     * @param role role
     * @return List
     */
    List<String> listUserIdByRole(String role);

    /**
     * 查询Admin的孩子
     * @param userId userId
     * @return List
     */
    List<String> listSonUserIds(String userId);

    /**
     *
     * @param token token
     * @param userServiceRole userServiceRole
     * @param serviceName serviceName
     * @param checkTvuccDB checkTvuccDB
     * @return Result
     * @throws IOException IOException
     */
    Result<LoginUser> globalGetLoginUser(String token, boolean userServiceRole, String serviceName, boolean checkTvuccDB) throws IOException;

    /**
     * check 用户在cc和userservice的存在情况
     * @param email email
     * @param loginUser loginUser
     * @param session session
     * @return CheckUserVo
     */
    CheckUserVo checkUser(LoginUser loginUser, String session, String email);

    /**
     *
     * @return Result
     */
    Result<Object> initOriginParam();
    
    /**
     * 
     * 版权归属：2019-TUVNETWORKS
     * 项目名：tvucc-user
     * 类名：UserService
     * 方法名：getLoginUserByEmail
     * 描述:TODO<p>根据用户id获取用户登录信息</p>
     * 创建人：Gabrielliu(lk)
     * 创建时间：Oct 31, 2019 10:16:24 AM   
     * 修改人：   
     * 修改时间：   
     * 修改备注：
     * @param  userId userId
     * @throws Exception 编译
     * @return LoginUser

     *
     */
    LoginUser getLoginUserByUserId(String userId) throws Exception;

    /**
     *
     * @param userId userId
     * @return LoginUser
     * @throws Exception 编译
     */
     LoginUser getParentUserByUserId(String userId) throws Exception;

    /**
     * GridMarket 中GlobalGrid和GridRequest数量
     * @param userId userId
     * @return int
     */
    int countGridNotifyNum(String userId);

    /**
     *
     * @param param param
     * @return int
     */
    int moveUserToOtherAdmin(MoveUserToOtherAdminParam param);

    /**
     *
     * @param userId userId
     * @return User
     */
    User getParentUser(String userId);

    /**
     * user-group 删除用户的时候调用CC删除用户
     * @param userId userId
     * @return int
     */
    int deleteUser(String userId);

    /**
     *
     * @param email email
     * @return Result
     */
    Result getSessionByEmail(String email);
    
    /**
     * 
     * 版权归属：2020-TUVNETWORKS
     * 项目名：tvucc-user
     * 类名：UserService
     * 方法名：getUserListByParentUserId
     * 描述:TODO<p>根据父用户id查询子用户集合</p>
     * 创建人：Gabrielliu(lk)
     * 创建时间：2020年4月22日 下午1:30:19   
     * 修改人：   
     * 修改时间：   
     * 修改备注：  
     * @param parentUserId parentUserId
     * @param currentPageNum currentPageNum
     * @param everyPageNum everyPageNum
     * @param search search
     * @return Result
     * @throws Exception 编译
     *
     */
	 Result<Object> getUserListByParentUserId(String parentUserId,String search,Integer currentPageNum,Integer everyPageNum) throws Exception;

    /**
     *
     * @param loginUser loginUser
     * @param param param
     */
    void updateUserEmail(LoginUser loginUser, UpdateUserEmailParam param);

    /**
     *
     * @param loginUser loginUser
     * @param param param
     * @return ExcelData
     */
    ExcelData exportUser(LoginUser loginUser, SearchUserParam param);

    /**
     *
     * @param loginUser loginUser
     * @param userId userId
     * @return Result
     * @throws Exception 编译
     */
    Result deleteAccout(LoginUser loginUser,String userId) throws Exception;

    /**
     *
     * @param loginUser loginUser
     * @param userId userId
     * @param deleteSonAccountFlag deleteSonAccountFlag
     */
    void invalidateUser(LoginUser loginUser, String userId,boolean deleteSonAccountFlag);

    /**
     * 根据admin账号的id获取其所有的子账号
     * @param param param
     * @return PageInfo
     */
    PageInfo<GetUserByRoleIdVo> pageSonUserByParentUserId(PageSonUserParam param);

    /**
     * 根据admin账号的email获取其所有的子账号
     * @param  userParentEmail userParentEmail
     * @return Result
     */
    Result<List<UserInfoVo>> sonUserByParentUserEmail(String userParentEmail);

    /**
     * User already has exist in userGroup Service, and not exist in Cc Service, create user in Cc Service and role is user
     * @param userId userId
     * @param email email
     */
    void createUserInCcService(String  userId,String email);

    /**
     * 根据父账号id获取宣布子账号id
     * @param userId userId
     * @return 子账号集合
     */
    List<String> listSonUserIdByParentId(String userId);

    /**
     * 获取所有的admin用户
     * @return  获取所有的admin用户
     */
    List<User> getUserOfAdminAndHaveSonUser();
}
